import React, { Component } from 'react'
import { getUserToOwnerApi, changeUserToOwnerApi } from "../../apis/usersApi"
import { Button } from 'antd';

export default class CheckUser extends Component {
    state = {
        data: {}
    }
    componentDidMount() {
        this.obtainid()
    };
    obtainid = async () => {
        const _id = this.props.location.search.split("?")[1].split("=")[1]
        await this.setState({ _id })
        this.getUserToOwner(_id)
    }
    changeUserToOwner = async (a) => {
        try {
            if(a==1){
                this.state.data.checkStatus = "yes"
            }else{
                this.state.data.checkStatus = "noway"
            }
            const dalt = this.state.data
            const data = await changeUserToOwnerApi(dalt)
            this.props.history.push("/main/usersList" )
        } catch (error) {
            console.log(error, "1212");
        }
    };
    getUserToOwner = async (_id) => {
        try {
            const data = await getUserToOwnerApi({ _id })
            this.setState({ data })
        } catch (error) {
            console.log(111, error)
        }
    }
    render() {
        return (
            <div className="userbox">
                <h3> 用户的信息以及身份的审核</h3>
                <p><b>姓名</b>：{this.state.data.name}</p>
                <p><b>账号</b>：{this.state.data.username}</p>
                <p><b>钱包</b>：{this.state.data.money}</p>
                <p><b>电话</b>：{this.state.data.phone}</p>
                <p><b>身份证</b>：{this.state.data.idCard}</p>
                <p><b>地址</b>：{this.state.data.address}</p> 
                <Button type="primary" danger onClick={() => this.changeUserToOwner(1)}>
                    审核通过
                </Button>
                <Button type="primary" danger onClick={() => this.changeUserToOwner(0)} className="mar">
                    审核不通过
                </Button>
            </div>
        )
    }
}
